
package edu.tongji.jiaowu.dao.jdbc;
 
import java.util.List;

import edu.tongji.jiaowu.dao.EvtStudentDao;
import com.tongji.quickCRUDQ.define.Row;
import com.tongji.quickCRUDQ.model.CommonBean;
import com.tongji.quickCRUDQ.dao.jdbc.BaseDaoJdbc;

public class EvtStudentDaoJdbc extends BaseDaoJdbc implements EvtStudentDao {
	String tableName="T_EVT_STUDENT";
	String beanName="evtStudent";
	
	public CommonBean createEvtStudent(){
		CommonBean evtStudents=this.createBean(tableName,beanName);
                return evtStudents;		
	}
	
/*
	public CommonBean findEvtStudents(String refid) {
		CommonBean evtStudents=this.createEvtStudent();
		String sql="select * from T_EVT_STUDENT where refid=?";
		List data=this.getCommonDao().select(sql,new String[]{refid});
		evtStudents.addData(data);
                return evtStudents;
       }
*/
	public CommonBean findEvtStudentById(String id) {
		CommonBean evtStudents=this.createEvtStudent();
		String sql="select * from T_EVT_STUDENT where id=?";
		List data=this.getCommonDao().select(sql,new String[]{id});
		evtStudents.addData(data);
    return evtStudents;
  }
  
	public CommonBean findAllEvtStudents() {
		CommonBean evtStudents=this.createEvtStudent();
		String sql="select * from T_EVT_STUDENT ";
		List data=this.getCommonDao().select(sql,new String[]{});
		evtStudents.addData(data);
    return evtStudents;
  }
	public void insertEvtStudent(CommonBean evtStudentBean){
		List data=evtStudentBean.getData();
		Row row=this.getRow(tableName);
		this.getCommonDao().templateBatchInsert(row,data,this.getIdGenerator());
	}
	public void updateEvtStudent(CommonBean evtStudentBean){
		List data=evtStudentBean.getData();
		Row row=this.getRow(tableName);
		this.getCommonDao().templateBatchUpdate(row,data);
	}

	public void init(String year, String semester) {
		String sql1="delete from T_EVT_STUDENT where school_year=? and school_semester=?";
		String sql2="insert into T_EVT_STUDENT(ID,SCHOOL_YEAR,SCHOOL_SEMESTER,STUDENT_NO,COURSE_TYPE,CLASS_NO,DEPARTMENT_NO,course_name,TEACHER_NO,teacher_name,IS_FINISH,NOTE)\n "+
					"SELECT     dbo.get_seq_d() ID, a.SCHOOL_YEAR, a.SCHOOL_SEMESTER, a.STUDENT_NO, '01' course_type,a.CLASS_NO,b.college_no,b.course_name, b.TEACHER_NO,b.teacher_name,'N' is_finish,null note\n" +
					"FROM         T_ELECTIVE_RESULT AS a INNER JOIN\n" + 
					"             (select distinct school_year,school_semester,class_no,teacher_no,teacher_name,course_name,college_no from V_TASK_PHASE) AS b ON a.SCHOOL_YEAR = b.SCHOOL_YEAR\n" + 
					"            AND a.SCHOOL_SEMESTER = b.SCHOOL_SEMESTER AND a.CLASS_NO = b.CLASS_NO\n" + 
					"where a.school_year=? and a.school_semester=?";
		getCommonDao().updateRecord(sql1, new String[]{year,semester});
		getCommonDao().updateRecord(sql2, new String[]{year,semester});
	}

	public CommonBean findEvTeachers(String year, String semester, String sno) {
		String sql="select * from t_evt_student where school_year=? and school_semester=? and student_no=? order by is_finish,COURSE_NAME";
		List data=getCommonDao().select(sql,new String[]{year,semester,sno});
		CommonBean bean=createBean(tableName, beanName);
		bean.addData(data);
		return bean;
	}

	public void finish(String id, String note) {
		String sql="update T_EVT_STUDENT set is_finish='Y',note=? where id=?";
		getCommonDao().updateRecord(sql, new String[]{note,id});
	}

	public void statistic(String year, String semester) {
		getCommonDao().callProcedure("p_evt_statistic", new int[]{1,1}, new String[]{year,semester});
	}
}

